//
//  PackageHeadView.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/10/8.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

@objc protocol PackageHeadViewDelegate {
    @objc optional func selectBankCard(index:Int)
}

class PackageHeadView: UIView {

    weak var delegate : PackageHeadViewDelegate?
    fileprivate let dataSource = [creditCard,debitCard]
    
    init() {
        super.init(frame: .zero)
        
        self.backgroundColor = UIColor.white
        
        let segmentedControl = UISegmentedControl.init(items: dataSource)
        segmentedControl.selectedSegmentIndex = 0
        segmentedControl.tintColor = UIColor.phoneColor()
        segmentedControl.addTarget(self, action: #selector(indexDidChangeForSegmentedControl(sender:)), for: .valueChanged)
        self.addSubview(segmentedControl)
        
        segmentedControl.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(RATIO(maxNum: 20))
            make.right.equalToSuperview().offset(RATIO(maxNum: -20))
            make.centerY.equalToSuperview()
            make.height.equalTo(RATIO_H(maxNum: 30))
        }
    }
    
    //MARK: 选择内容
    @objc fileprivate func indexDidChangeForSegmentedControl(sender:UISegmentedControl) {
        
        self.delegate?.selectBankCard!(index: sender.selectedSegmentIndex)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
